package com.jyw.business.ins.domain.vo.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.ins.domain.InsTask;
import com.jyw.business.ins.domain.InsTaskRectify;
import com.jyw.business.obstacles.domain.ObsOrderFault;
import com.jyw.business.obstacles.domain.ObsOrderInfo;
import com.jyw.business.obstacles.domain.dto.wechat.WechatOrderAddDto;
import com.jyw.business.obstacles.domain.vo.web.TransferOrderVO;
import com.jyw.common.annotation.Conversion;
import com.jyw.common.annotation.Excel;
import com.jyw.common.enums.ConversionType;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.domain.vo.SimpleFileVo;
import com.jyw.system.utils.ConversionUtil;
import com.jyw.system.utils.FileUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

import java.util.Date;
import java.util.List;

/**
 * @author 沈峻
 * @ClassName RecordDetail
 * @Description 巡检记录详情
 * @Date 2023/10/7 11:43
 **/
@ApiModel("巡检记录详情")
@Data
@FieldNameConstants
@NoArgsConstructor
public class RecordDetailVo {
    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("编码")
    private String code;

    @ApiModelProperty("巡检名称")
    private String name;

    @ApiModelProperty("巡检人")
    @Conversion(value = ConversionType.USER,name = Fields.inspectUserName)
    private Long inspectUserId;
    
    @ApiModelProperty("巡检人名称")
    private String inspectUserName;

    @ApiModelProperty("巡检时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date inspectionTime;

    @ApiModelProperty("巡检结果")
    private Integer result;

    @ApiModelProperty("详细说明")
    private String elaborate;

    @ApiModelProperty("过程照片")
    private List<SimpleFileVo> inspectionPhotos;

    @ApiModelProperty("录音")
    private String inspectionSound;

    /** 处理办法（1限期整改 2转工单） */
    @ApiModelProperty("处理办法（1限期整改 2转工单）")
    private Integer handleMethod;

    @ApiModelProperty("巡检内容")
    private List<TaskItemVo> taskItemVoList;

    @ApiModelProperty("限期整改内容")
    private RecordTaskRectifyVo rectify;


    @ApiModelProperty("转工单信息")
    private TransferOrderVO transferOrder;

    @ApiModelProperty("工单号")
    private String orderNum;
    /**
     * 构造巡检记录
     * @param task
     */
    public RecordDetailVo(InsTask task) {
        BeanUtils.copyProperties(task,this);
        setInspectionPhotos(FileUtils.IdToFile(task.getInspectionPhotos()));
    }

    /**
     * 设置整改内容
     * @param rectify
     */
    public void setTaskRectify(InsTaskRectify rectify) {
        RecordTaskRectifyVo recordTaskRectifyVo = new RecordTaskRectifyVo();
        BeanUtils.copyProperties(rectify,recordTaskRectifyVo);
        setRectify(ConversionUtil.conversion(recordTaskRectifyVo,RecordTaskRectifyVo.class));
    }

    public void setObjInfo(InsObjInfo objInfo) {
        setName(objInfo.getName());
        setCode(objInfo.getCode());
    }

    /**
     * 封装转工单信息
     * @param orderInfo
     * @param orderFault
     * @param wechatOrderAddDto
     */
    public void setTransferOrderInfo(ObsOrderInfo orderInfo, ObsOrderFault orderFault, WechatOrderAddDto wechatOrderAddDto) {
        TransferOrderVO vo = new TransferOrderVO();
        BeanUtils.copyProperties(wechatOrderAddDto,vo);
        vo.setReportTime(orderInfo.getCreateTime());
        vo.setReportUser(orderFault.getCreateUser());
        vo = ConversionUtil.conversion(vo,TransferOrderVO.class);
        setTransferOrder(vo);
    }
}
